package com.chuanyang.driverh.mainhome.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.utils.eventbus.MessageData;

import java.util.List;

public class SystemMessageAdapter extends BaseAdapter {

    private List<MessageData.MesageDataBean> systemMessageBeanList;
    private LayoutInflater mInflater;
    private Context mContext;
    private int status;


    public SystemMessageAdapter(Context activity, List<MessageData.MesageDataBean> systemMessageBeanList) {
        this.systemMessageBeanList = systemMessageBeanList;
        mContext = activity;
        mInflater = LayoutInflater.from(activity);
    }

    public void setData(List<MessageData.MesageDataBean> systemMessageBeanList) {
        this.systemMessageBeanList=systemMessageBeanList;
        notifyDataSetChanged();
    }
    /**
     * 添加数据集合
     *
     * @param objects
     */
    public void addAll(List<MessageData.MesageDataBean> objects) {
           systemMessageBeanList.addAll(objects);
            notifyDataSetChanged();

    }
    /**
     * 清空列表
     */
    public void clear() {
        systemMessageBeanList.clear();
            notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return systemMessageBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return systemMessageBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_systemmessage_list, null);
            holder = new ViewHolder();
            holder.tv_message_time = (TextView) convertView.findViewById(R.id.tv_message_time);
            holder.tv_message_content = (TextView) convertView.findViewById(R.id.tv_message_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MessageData.MesageDataBean  bean=systemMessageBeanList.get(position);
        holder.tv_message_time.setText(bean.getSendTime());
        holder.tv_message_content.setText("\u3000\u3000"+bean.getMessageContent());
        return convertView;
    }

    public class ViewHolder {
        public TextView tv_message_time;
        public TextView tv_message_content;
    }
}
